export function getComponents(imports) {
  const components = {}

  // user/:id -> user/:Id.vue -> named route start with :
  Object.keys(imports).forEach(path => {

    const uri = path
      // clean path
      .replace(/\.\.\/pages|\.vue|index\/Index|\/Index/g, '')
      // camel case to kebab case
      .replace(/(?=[a-z])([A-Z])/g, m => '-' + m.toLowerCase())
      .replace(/\/\:?([A-Z])/g, m => m.toLowerCase())

    if (uri) {
      components[
        uri.replace(/_/g, '')
      ] = imports[path]
    }
  })

  return components
}

export function getRouteName(path) {
  if (typeof path !== 'string') return path

  const name = path
    .replace(/[:]/g, '')
    .replace(/[/-]+(\w)/g, (a, m) => m.toUpperCase())
    .replace(/^\w/g, m => m.toUpperCase())

  return name === '/' ? 'Index' : name
}
